using UnityEngine;
using System.Collections;

public class EnemyCharacterBehaviour : CharacterBehaviour
{
	private float timeOnIdle = 3;
	private float timeWalking = 1;
	private bool right = true;
	
	protected override void Awake()
	{
		base.Awake();
	}
	
	protected override void Update() 
	{
		if(!onHit && hp > 0)
		{
			if(timeWalking > 0)
			{
				timeWalking -= Time.deltaTime;
				TryMove(right);
				
				if(timeWalking <= 0)
				{
					StartCoroutine(WaitIdle());
				}
			}
			
			base.Update();
		}
	}
	
	private IEnumerator WaitIdle()
	{
		yield return new WaitForSeconds(timeOnIdle);
		
		timeWalking = Random.Range(1, 1.5f);
		
		right = !right;
	}
}